//
//  ViewController.m
//  UI_抓接口测试
//
//  Created by dllo on 15/10/22.
//  Copyright (c) 2015年 Forlosan. All rights reserved.
//

#import "ViewController.h"
#import "AFNetworking.h"
#import "WebViewController.h"
#import "FirstViewController.h"


@interface ViewController ()
@property (nonatomic,copy) NSString *name;
@property (nonatomic, retain) UIImageView *imageView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    self.view.backgroundColor = [UIColor lightGrayColor];
    
#if 0
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    NSString *sss =@"http://a3.go2yd.com/Website/channel/best-news?appid=food2&cend=30&cstart=0&cv=2.0.4&distribution=com.apple.appstore&fields%5B%5D=title&fields%5B%5D=url&fields%5B%5D=source&fields%5B%5D=date&fields%5B%5D=image&fields%5B%5D=image_urls&fields%5B%5D=comment_count&fields%5B%5D=like&infinite=true&net=wifi&platform=0&refresh=1&version=010904";
    
    //    NSString *url_string = [sss stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil]; 代表支持所有的接口类型
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
     //添加cookie的方法
    [manager.requestSerializer setValue:@"JSESSIONID=SAH0gO7Ju8QlSCgItd7HYQ" forHTTPHeaderField:@"Cookie"];
    
    
    [manager GET:sss parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSLog(@"%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        NSLog(@"没有");
    }];
    
#endif
    
#if 1
    
    AFNetworkReachabilityManager *netWorkManager = [AFNetworkReachabilityManager sharedManager];
    
    NSString *sss =@"http://chanyouji.com/api/articles.json?page=1";
    
    //    NSString *url_string = [sss stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    //[NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil]; 代表支持所有的接口类型
    
    AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes= [NSSet setWithObjects:@"text/plain",@"text/json",@"application/json",@"text/javascript",@"text/html",nil];
    
    //添加cookie的方法
//    [manager.requestSerializer setValue:@"Hm_lvt_a641a94f2a28291909af4213f237173a=1445501567; pgv_pvi=9344011264; yka_gid=9cac1801-2f4e-fa4f-af24-687bdc9f6626; yka_ph=%7B%20%27value%27%3A%20%2700000000000000000000000000001%27%2C%27lastdate%27%3A%20%271445443200000%27%7D" forHTTPHeaderField:@"Cookie"];
    
//    [manager.requestSerializer setValue:@"E856C59A-F2C9-4B91-8838-C01E119E9832" forHTTPHeaderField:@"idfa"];
//    [manager.requestSerializer setValue:@"B431A13B-627B-4984-9932-FE4C6313CCEF" forHTTPHeaderField:@"hu"];
    
    [manager POST:sss parameters:Nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"%@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"%@", error);
    }];
    
#endif
    
    
    
    
//    AFHTTPSessionManager *manager1 = [AFHTTPSessionManager manager];
//    manager1.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/json", @"text/javascript", @"text/html", @"application/json", nil];
//    [manager1 POST:@"http://mobservices3.yoka.com/service.ashx" parameters:Nil success:^(NSURLSessionDataTask *task, id responseObject) {
//        NSLog(@"POST = %@", responseObject);
//    } failure:^(NSURLSessionDataTask *task, NSError *error) {
//        NSLog(@"SHIBAI");
//    }];
    
    
    
    
    WebViewController *web = [[WebViewController alloc] init];
    web.url = @"http://www.ttyst.net/27937.html";
    [self.navigationController pushViewController:web animated:YES];
    [web release];
    
    
    NSMutableArray *array = [NSMutableArray arrayWithObjects:@"1", @"2", @"3", @"9", @"4", @"5", @"6", @"7", @"8", nil];
    
    for (int i = 0; i < array.count; i++) {
        
        self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(20 + 118 * (i % 3), 80 + 118 * (i / 3), 98, 98)];
        self.name = [array objectAtIndex:i];
        self.imageView.image = [UIImage imageNamed:self.name];
        self.imageView.backgroundColor = [UIColor whiteColor];
    
        [self.view addSubview:self.imageView];
        [self.imageView release];
        
        self.imageView.userInteractionEnabled = YES;
        self.imageView.tag = 100 + i;
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:tag:)];
        [self.imageView addGestureRecognizer:tap];
        [tap release];
        
    }

    
}

-(void)tapAction:(UITapGestureRecognizer *)tap tag:(NSInteger)tag
{
    
    FirstViewController *first = [[FirstViewController alloc] init];
    
    first.string = self.name;
    
    [self presentViewController:first animated:YES completion:^{
        
        
    }];
    
    [first release];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
